# -*- coding:utf-8 -*-

import os

from flask import Blueprint
from flask_restful import Api

from api.resource import register_resources
from .account import LoginView
from .account import LogoutView
from .account import AuthWithKeyView

HERE = os.path.abspath(os.path.dirname(__file__))

# 类Api主要用于创建API路由，需要注册，减少了手动编写路由和请求解析的代码量，不然就要手动编写@app.route('/api/...')

# 注册一个account账号 蓝图实例，并指定前缀
blueprint_account = Blueprint('account_api', __name__, url_prefix='/api')
account_rest = Api(blueprint_account)
# 添加API视图函数对象
account_rest.add_resource(LoginView, LoginView.url_prefix)
account_rest.add_resource(LogoutView, LogoutView.url_prefix)
account_rest.add_resource(AuthWithKeyView, AuthWithKeyView.url_prefix)


# 注册一个acl子系统的 蓝图实例，并指定前缀
blueprint_acl_v1 = Blueprint('acl_api_v1', __name__, url_prefix='/api/v1/acl')
rest = Api(blueprint_acl_v1)
register_resources(os.path.join(HERE, "acl"), rest)


# 注册一个cmdb子系统的 蓝图实例，并指定前缀
blueprint_cmdb_v01 = Blueprint('cmdb_api_v01', __name__, url_prefix='/api/v0.1')
rest = Api(blueprint_cmdb_v01)
register_resources(os.path.join(HERE, "cmdb"), rest)


# 注册一个common_setting模块的 蓝图实例，并指定前缀
blueprint_cs_v1 = Blueprint('common_setting_api_v1', __name__, url_prefix='/api/common-setting/v1')
rest = Api(blueprint_cs_v1)
register_resources(os.path.join(HERE, "common_setting"), rest)

